package com.ccp.dev.workflow.model.bpm;

import com.ccp.dev.core.basic.model.BaseModel;
import com.ccp.dev.core.basic.util.PropertyUtil;
import com.ccp.dev.core.util.AppUtil;
import com.ccp.dev.workflow.dao.BpmBusLinkDao;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 对象功能:业务数据关联表 Model对象
 *
 * @version 2019-07-18
 */
@Component
public class BpmBusLink extends BaseModel {

    // 对应 P_TABLE_UNCREATED ,未创建实体表的都放进去
    public static final String TABLE_UNCREATED = "TABLE_UNCREATED";

    // 作为分区的列
    public static final String BUS_FORM_TABLE = "BUS_FORM_TABLE";

    /**
     * 业务数据
     */
    public static final Integer BUS_STATUS_BUSINESS = 0;
    /**
     * 流程运行。
     */
    public static final Integer BUS_STATUS_RUNNING = 1;
    /**
     * 流程结束
     */
    public static final Integer BUS_STATUS_END = 2;
    /**
     * 流程手工结束
     */
    public static final Integer BUS_STATUS_MANUAL_END = 3;

    /**
     * 主键
     */
    protected String busId;

    /**
     * 对应关联表主键 (表主键为number类型)
     */
    protected Long busPk;

    /**
     * 对应关联表主键(表主键为字符串类型)
     */
    protected String busPkstr;

    /**
     * 对应关联表 表明
     */
    protected String busFormTable;

    /**
     * 流程定义ID
     */
    protected String busDefId;

    /**
     * 流程运行ID
     */
    protected String busFlowRunid;

    /**
     * 发起人ID
     */
    protected String busCreatorId;

    /**
     * 发起人
     */
    protected String busCreator;

    /**
     * 发起组织
     */
    protected String busOrgId;

    /**
     * 组织名称
     */
    protected String busOrgName;

    /**
     * 发起时间
     */
    protected java.util.Date busCreatetime;

    /**
     * 最后更新人ID
     */
    protected String busUpdid;

    /**
     * 最后更新人
     */
    protected String busUpd;

    /**
     * 最后更新时间
     */
    protected java.util.Date busUpdtime;

    /**
     * 业务数据状态(0,业务数据,1,流程运行,2,流程结束,3,手工结束)
     */
    protected Integer busStatus = 0;

    public void setBusId(String busId) {
        this.busId = busId;
    }

    /**
     * 返回 主键
     *
     * @return
     */
    public String getBusId() {
        return this.busId;
    }

    public void setBusPk(Long busPk) {
        this.busPk = busPk;
    }

    /**
     * 返回 对应关联表主键
     *
     * @return
     */
    public Long getBusPk() {
        return this.busPk;
    }

    public void setBusPkstr(String busPkstr) {
        this.busPkstr = busPkstr;
    }

    /**
     * 返回 对应关联表主键(字符串)
     *
     * @return
     */
    public String getBusPkstr() {
        return this.busPkstr;
    }

    public void setBusDefId(String busDefId) {
        this.busDefId = busDefId;
    }

    /**
     * 返回 流程定义ID
     *
     * @return
     */
    public String getBusDefId() {
        return this.busDefId;
    }

    public void setBusFlowRunid(String busFlowRunid) {
        this.busFlowRunid = busFlowRunid;
    }

    /**
     * 返回 流程运行ID
     *
     * @return
     */
    public String getBusFlowRunid() {
        return this.busFlowRunid;
    }

    public void setBusCreatorId(String busCreatorId) {
        this.busCreatorId = busCreatorId;
    }

    /**
     * 返回 发起人ID
     *
     * @return
     */
    public String getBusCreatorId() {
        return this.busCreatorId;
    }

    public void setBusCreator(String busCreator) {
        this.busCreator = busCreator;
    }

    /**
     * 返回 发起人
     *
     * @return
     */
    public String getBusCreator() {
        return this.busCreator;
    }

    public void setBusOrgId(String busOrgId) {
        this.busOrgId = busOrgId;
    }

    /**
     * 返回 发起组织
     *
     * @return
     */
    public String getBusOrgId() {
        return this.busOrgId;
    }

    public String getBusFormTable() {
        return busFormTable;
    }

    public void setBusFormTable(String busFormTable) {
        this.busFormTable = busFormTable;
    }

    public void setBusOrgName(String busOrgName) {
        this.busOrgName = busOrgName;
    }

    /**
     * 返回 组织名称
     *
     * @return
     */
    public String getBusOrgName() {
        return this.busOrgName;
    }

    public void setBusCreatetime(java.util.Date busCreatetime) {
        this.busCreatetime = busCreatetime;
    }

    /**
     * 返回 发起时间
     *
     * @return
     */
    public java.util.Date getBusCreatetime() {
        return this.busCreatetime;
    }

    public void setBusUpdid(String busUpdid) {
        this.busUpdid = busUpdid;
    }

    /**
     * 返回 最后更新人
     *
     * @return
     */
    public String getBusUpdid() {
        return this.busUpdid;
    }

    public void setBusUpd(String busUpd) {
        this.busUpd = busUpd;
    }

    /**
     * 返回 最后更新人
     *
     * @return
     */
    public String getBusUpd() {
        return this.busUpd;
    }

    public void setBusUpdtime(java.util.Date busUpdtime) {
        this.busUpdtime = busUpdtime;
    }

    /**
     * 返回 最后更新时间
     *
     * @return
     */
    public java.util.Date getBusUpdtime() {
        return this.busUpdtime;
    }

    public Integer getBusStatus() {
        return busStatus;
    }

    public void setBusStatus(Integer busStatus) {
        this.busStatus = busStatus;
    }


    private static Boolean supportPartition = null;


    @Value("${mybatis.configuration.database-id}")
    private String dataType;

    /**
     * 判断是否支持分区表 目前支持 oracle mysql5.5 以上版本
     */
    public boolean isSupportPartition() {
        if (supportPartition != null) {
            return supportPartition;
        }
        String supportPartion = PropertyUtil.getByAlias("supportPartion", "1");
        if ("0".equals(supportPartion)) {
            supportPartition = false;
            return false;
        }
        if ("oracle".equals(dataType)) {
            supportPartition = true;
        } else if ("mysql".equals(dataType)) {
            BpmBusLinkDao dao = AppUtil.getBean(BpmBusLinkDao.class);
            String mysqlVersion = dao.getMysqlVersion();
            double varsion = Double.parseDouble(mysqlVersion.substring(0, 3));
            if (varsion >= 5.5) {
                supportPartition = true;
            } else {
                supportPartition = false;
            }
        } else {
            supportPartition = false;
        }
        return supportPartition;
    }

    @Override
    public String toString() {
        return "BpmBusLink{" +
                "busId='" + busId + '\'' +
                ", busPk='" + busPk + '\'' +
                ", busPkstr='" + busPkstr + '\'' +
                ", busFormTable='" + busFormTable + '\'' +
                ", busDefId='" + busDefId + '\'' +
                ", busFlowRunid='" + busFlowRunid + '\'' +
                ", busCreatorId='" + busCreatorId + '\'' +
                ", busCreator='" + busCreator + '\'' +
                ", busOrgId='" + busOrgId + '\'' +
                ", busOrgName='" + busOrgName + '\'' +
                ", busCreatetime=" + busCreatetime +
                ", busUpdid='" + busUpdid + '\'' +
                ", busUpd='" + busUpd + '\'' +
                ", busUpdtime=" + busUpdtime +
                ", busStatus=" + busStatus +
                '}';
    }
}